#include "Tools.h"

namespace Tools
{
	std::pair<std::string,std::string> Separate(std::string theInput, char theSeparator,bool theFirst)
	{
		std::string aPath;
		std::string aName;
		std::pair<std::string,std::string> aResult;
		std::string::size_type aIndex = std::string::npos;

		if(theFirst)
			aIndex = theInput.find_first_of(theSeparator);
		else
			aIndex = theInput.find_last_of(theSeparator);
		
		if( aIndex == std::string::npos)
			return aResult;

		aPath = theInput.substr(0,aIndex);
		aName = theInput.substr(aIndex+1);
		
		aResult = make_pair(aPath,aName);

		return aResult;
	}

	std::vector<std::string> Split(std::string theInput,std::string splitBy)
	{
		std::vector<std::string> aResult;
		std::string::size_type pos = std::string::npos;
		bool stuffToSeparate = false;
		
		while( (pos=theInput.find_first_of(splitBy))!=std::string::npos )
		{
			std::string subString = theInput.substr(0,pos);
			aResult.push_back(subString);
			theInput = theInput.substr(pos+1);
			stuffToSeparate = true;
		}
		
		if(!theInput.empty() && stuffToSeparate)
		{
			aResult.push_back(theInput);
		}

		return aResult;
	}

	std::string GetPath(std::string thePath)
	{
		std::size_t last_index = thePath.find_last_of('/');
		if(last_index == std::string::npos)
		{
			std::string empty;
			return empty;
		}

		return thePath.erase(last_index+1);
	}
}
